package gsd.gaudi.common.model.log;

import java.io.Serializable;
import java.util.LinkedList;

public class GaudiListener implements Serializable{

	private static final long serialVersionUID = 1L;

	private String widgetid;
	private String listenerid;
	private LinkedList<GaudiAccess> variableAccess;

	public GaudiListener(String wid, String lid){
		this.setWidgetid(wid);
		this.setListenerid(lid);
		this.variableAccess = new LinkedList<GaudiAccess>();
	}
	
	public void addAccess(String wid, Serializable value, boolean write, boolean read){
		GaudiAccess newaccess = new GaudiAccess(wid, value, write, read);
		this.variableAccess.add(newaccess);
	}

	public void setWidgetid(String widgetid) {
		this.widgetid = widgetid;
	}

	public String getWidgetid() {
		return widgetid;
	}

	public void setListenerid(String listenerid) {
		this.listenerid = listenerid;
	}

	public String getListenerid() {
		return listenerid;
	}
	
	public LinkedList<GaudiAccess> getAccesses(){
		return this.variableAccess;
	}
	
	public String toString(){
		String res = "";
		res += "-Invoked Listener "+this.listenerid+" at " + this.widgetid +"\n";
		if(!this.variableAccess.isEmpty()){
			for(GaudiAccess a : this.variableAccess){
				res += "\t" + a.toString();
			}
		}
		return res;
	}
	
	public GaudiListener copyMe(){
		GaudiListener nseq = new GaudiListener(this.widgetid, this.listenerid);
		
		for(GaudiAccess ga : this.variableAccess){
			nseq.variableAccess.addLast(ga.copyMe());
		}
		
		return nseq;
	}
	
}
